package com.bkgy.modular.subjectQuery.controller;

import com.alibaba.fastjson.JSONObject;
import com.bkgy.modular.subjectQuery.entity.ShareData;
import com.bkgy.modular.subjectQuery.service.CurveService;
import com.bkgy.modular.subjectQuery.service.RightDataTabService;
import com.bkgy.modular.subjectQuery.service.SideDataService;
import com.bkgy.sys.common.entity.ResultData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author ZhuHongKai
 * @version 1.0
 * @ClassName SubjectQueryController
 * @date 2023/1/7 9:57
 */
@RestController
@RequestMapping("/SubjectQuery")
public class SubjectQueryController {
    @Resource
    private SideDataService sideDataService;

    @Autowired
    private ApplicationContext applicationContext;

    @Resource
    private CurveService curveService;

    /**
     * 主题查询数据接口
     * @param jsonObject
     * @return
     */
    @PostMapping("/findByData")
    public ResultData findByData(@RequestBody JSONObject jsonObject) {
        return sideDataService.findByData(jsonObject);
    }

    @PostMapping("/findByRightData")
    public ResultData findByRightData(@RequestBody JSONObject jsonObject) {
        Integer pageIndex = jsonObject.getInteger("pageIndex");
        Integer pageSize = jsonObject.getInteger("pageSize");
        JSONObject condition = jsonObject.getJSONObject("condition");
        ShareData shareData = new ShareData();
        shareData.setPaymentType(condition.getString("paymentType"));
        RightDataTabService contextBean = applicationContext.getBean(shareData.getPaymentType(), RightDataTabService.class);
        return contextBean.findByRightData(
                pageIndex,
                pageSize,
                condition.getString("coil_id"),
                condition.getString("hot_coil_id"),
                shareData);
    }

    /**
     * 根据key查询热轧曲线
     * @return
     */
    @PostMapping("/findCurveData")
    public ResultData findCurveData(@RequestBody JSONObject jsonObject) {
        return curveService.findCurveData(jsonObject);
    }

    /**
     * 根据key查询冷轧曲线
     * @param jsonObject
     * @return
     */
    @PostMapping("/findColdRollingData")
    public ResultData findColdRollingData(@RequestBody JSONObject jsonObject) {
        return curveService.findColdRollingData(jsonObject);
    }
}
